var mysql = require('mysql');
// const TripleDES = require('crypto-js/tripledes');
const CryptoJS = require('crypto-js')
let config = {
    host: '119.29.24.107',
    user: 'layik',
    password: 'BtPZFNeXx67frE7x',
    database: 'layik'
};
let pool = mysql.createPool(config);
exports.Mysql = function (sql) {
    return new Promise((resolve, reject) => {
        pool.getConnection(function (err, connection) {
            if (err) {
                reject(err)
            }
            connection.query(sql, function (error, results, fields) {
                //将链接返回到连接池中，准备由其他人重复使用
                connection.release();
                if (error) throw error;
                //执行回调函数，将数据返回
                resolve(results)
            });
        });
    })
};
exports.validateParams = function (map = {}) {
    for (prop of map) {
        if (typeof (prop) != map[prop] || map[prop] == undefined) {
            return false;
        }
    }
    return true;
}

// TripleDES 对称 解密
exports.TripleDecrypt = function (message) {
    return CryptoJS.TripleDES.decrypt(message, 'YusupTurak').toString(CryptoJS.enc.Utf8);
}
// TripleDES 对称 加密
exports.TripleEncrypt = function (message) {
    return CryptoJS.TripleDES.encrypt(message, "YusupTurak").toString();
}
